#include "light.h"

#include "primitive.h"
#include "material.h"
#include "scene.h"

namespace csupbr {

    bool VisiilityTest::is_occluded(std::shared_ptr<Scene>scene) const {
        return !scene->intersectP(li_isct.newRay(normalize(sp_isct.pHit - li_isct.pHit)), true);
    }

    Spectrum DirectLight::sample_li(LightRecord &lRec, const Intersection &spit,
                                    const Point2f &sample, Float &pdf) const {
        lRec.wi = -this->direct;
        
        return li;
    }

    Spectrum PointLight::sample_li(LightRecord &lRec, const Intersection &spit,
                                   const Point2f &sample, Float &pdf) const {
        Point3f center = (*l2o)(Point3f{0.f,0.f,0.f});
        lRec.wi = normalize(center - spit.pHit);
        Intersection liit;
        liit.pHit = center;
        lRec.visibility = VisiilityTest(spit, std::forward<Intersection>(liit));
        pdf = 1.f;
        return li;
    }

    Spectrum DiffuseAreaLight::sample_li(LightRecord &lRec, const Intersection &spit,
                                         const Point2f &sample, Float &pdf) const {
        return li;
    }
}